<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateBlogsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('blogs', function (Blueprint $table) {
            // Set DataBase Engine
            $table->engine = 'InnoDB';
            // Set Table Structure
            $table->id();
            $table->string('title');
            $table->text('content');
            $table->unsignedBigInteger('classify_id')->nullable();
            $table->unsignedBigInteger('author_id');
            $table->integer('like_count')->default(0);
            $table->integer('comment_count')->default(0);
            $table->softDeletes();
            $table->timestamps();
            // Foreign Key
            $table->foreign('author_id')
                ->references('id')
                ->on('users')
                ->onDelete('cascade');
            $table->foreign('classify_id')
                ->references('id')
                ->on('classify')
                ->onDelete('SET NULL');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('blogs');
    }
}
